package com.dh.core.common;

import com.dh.core.Exception.ExceptionEnum;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;
@Data
@NoArgsConstructor
@AllArgsConstructor
public class Results<T> implements Serializable {
    /**
     * 返回的code状态码
     */
    private Integer code;
    /**
     * 返回的描述
     */
    private String msg;
    /**
     * 返回的对象
     */
    private Object data;
    public Results(T data) {
        this.data = data;
        this.code = 200;
        this.msg = "操作成功";
    }
    public Results(T data, String msg) {
        this.data = data;
        this.msg = msg;
        this.code = 200;
    }
    public Results(T data, String msg, int code) {
        this.data = data;
        this.msg = msg;
        this.code = code;
    }
    public Results(int code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    public static <T> Results<T> success(T data) {
        return new Results<T>(data);
    }
    public static <T> Results<T> success(T data, String msg) {
        return new Results<T>(data, msg);
    }
    public static <T> Results<T> fail(ExceptionEnum exceptionEnum) {
        return new Results<T>(exceptionEnum.getCode(),exceptionEnum.getMessage(),null);
    }


}
